////////////////////////////////
//main.lua
//Entry point for application.
//WORKS
////////////////////////////////

require( "mysql" )
if(mysql==nil) then
	print("Error: MySQL module needed. Please install. Loading aborted.")
	return
end
require("socket")
if(socket==nil) then
	print("Error: WinSock module needed. Please install. Loading aborted.")
	return
end

//Debug info. For testing.
sid="STEAM_0:0:8229202"


//Global table, everything goes in here.
bbb={}
bbb.settings={}
bbb.commands={}
bbb.t={}
bbb.types={}
bbb.users={}

bbb.luabase="bbb/"

bbb.files={}
if(SERVER) then //Server only...
	table.insert(bbb.files,"util.lua")
	table.insert(bbb.files,"defines.lua")
	table.insert(bbb.files,"commandsys.lua")
	table.insert(bbb.files,"tableparse.lua")
	table.insert(bbb.files,"settings.lua")
	table.insert(bbb.files,"mysql.lua")
	table.insert(bbb.files,"util.lua")
	table.insert(bbb.files,"typesys.lua")
	table.insert(bbb.files,"usersys.lua")
	table.insert(bbb.files,"types.lua")
	table.insert(bbb.files,"funcdefine.lua")
	table.insert(bbb.files,"config.lua")
end
if(CLIENT) then //Client only...

end
/*
if(SERVER) then
	AddCSLuaFile("autorun/bbb.lua") //The clientside autoloader
	AddCSLuaFile(bbb.luabase.."main.lua") //This file, run it on the client
	for k,v in ipairs(bbb.files) do
		AddCSLuaFile(bbb.luabase..v)
	end
end
*/
for k,v in ipairs(bbb.files) do
	include(bbb.luabase..v)
end

bbb.files=nil


if(file.Exists("bbb")==false) then
	file.CreateDir("bbb")
end
if(file.Exists("bbb/users")==false) then
	file.CreateDir("bbb/users")
end
if(file.Exists("bbb/userbackup")==false) then
	file.CreateDir("bbb/userbackup")
end
if(file.Exists("bbb/fakesql")==false) then
	file.CreateDir("bbb/fakesql")
end

if(bbb.connect!=nil) then
	bbb.connect() //Connect
	bbb.verifytables() //Make sure it's cool.
end

if(bbb.usersysinit!=nil) then
	bbb.usersysinit()
end

if(bbb.savesettings!=nil) then
	bbb.settingstimer=true
	timer.Create("bbb.sst",5,0,bbb.savesettingstimer,5)
end
